<template>
  <div class="home">
    <!-- 头部 -->
    <van-search placeholder="请输入搜索商品" shape="round" @click="gotosearch" />

    <!-- 商品表头筛选 -->
    <van-tabs v-model="active">
      <van-tab :title="item.title" v-for="(item,index) in titleList" :key="index">
        <div class="title_two">
          <div>综合</div>
          <div @click="xiaoliang()">销量</div>
          <div>新品</div>
          <div>价格</div>
        </div>
        <!-- 内容 -->
        <div class="home_item">
          <div v-for="(items,index) in itemList" :key="index" v-show="item._id==items.cid">
            <div class="item_img_box">
              <img :src="items.pic" alt width="100%" />
            </div>
            <p>{{items.title}}</p>
            <p class="item_box_context">
              <span>￥：{{items.price}}</span>
              <s>{{items.old_price}}</s>
            </p>
          </div>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      contextindex: 0
    };
  },
  mounted() {
    // 一级表头
    this.$store.dispatch("TITLE");
    // 二级表头
    this.$store.dispatch("BOXITEM");
  },
  computed: {
    titleList() {
      return this.$store.state.titleList;
    },
    itemList() {
      return this.$store.state.itemList;
    },
  },
  methods: {
    gotosearch() {
      this.$router.push("/about");
    },
    xiaoliang(xb) {
      switch (1,2) {
        case 1:
          this.itemList.sort((a, b) => {
            return b.price - a.price;
          });
          break;
        case 2:
          this.itemList.sort((a, b) => {
            return a.price - b.price;
          });
          break;
      }
    }
  }
};
</script>
<style  scoped>
.home_item {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  background: white;
  font-size: 15px;
}
.title_two > div:hover {
  color: red;
}
.title_two {
  width: 65%;
  height: 40px;
  /* border: 1px solid red; */
  background: white;
  display: flex;
  justify-content: space-around;
  align-items: center;
  font-size: 14px;
}
.home_item > div {
  width: 45%;
  /* height: 200px; */
  border: 1px solid red;
  background: white;
  margin: 8px;
}
.item_box_context > span {
  color: red;
  margin-right: 20px;
}
.item_box_context > s {
  color: gray;
}
</style>
